package com.heima.comment.controller.v1;

import com.heima.comment.limiter.RequestLimiter;
import com.heima.comment.service.CommentReplyService;
import com.heima.model.comment.dtos.CommentRepayDto;
import com.heima.model.comment.dtos.CommentRepayLikeDto;
import com.heima.model.comment.dtos.CommentReplySaveDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/api/v1/comment_repay")
@RequiredArgsConstructor
@Api("评论回复相关接口")
public class CommentReplyController {
    private final CommentReplyService commentReplyService;
    private final RequestLimiter requestLimiter;


    @ApiOperation("保存评论")
    @PostMapping("/save")
    public ResponseResult addCommentReply(@RequestBody CommentReplySaveDto dto){
        return commentReplyService.addCommentReply(dto);
    }
    @ApiOperation("查询评论")
    @PostMapping("/load")
    public ResponseResult queryCommentReply(@RequestBody CommentRepayDto dto){
        String key = "request:myRequest"; // 可以根据实际情况定义键的格式
        if (requestLimiter.allowRequest(key)) {
            return commentReplyService.queryCommentReply(dto);
        } else {

            return ResponseResult.errorResult(AppHttpCodeEnum.PINGLUN_CHAXUN_CONGFU);
        }
    }
    @ApiOperation("点赞评论")
    @PostMapping("/like")
    public ResponseResult addOrDeleteReply(@RequestBody CommentRepayLikeDto dto){
        return commentReplyService.addOrDeleteReply(dto);
    }
}
